#define ADRENALIN_EXPORTS

#include "../include/Scene.h"

namespace Adrenalin
{
	Scene::Scene(stringw name)
		: _currentCamera(NULL)
	{
		_name = name;
		WRITELOG(L"Scene " + name + L" created", LOG_INFO);
	}

	Scene::~Scene()
	{ }

	void Scene::Close()
	{
		for( std::list<Adrenalin::ICamera*>::iterator i = _lstCameras.begin(); 
			 i != _lstCameras.end();
			 i++ )
		{
			(*i)->Release();
		}

		_lstCameras.clear();

		WRITELOG(L"Scene " + _name + L" released", LOG_INFO);
	}

	void Scene::AddCamera(ICamera* camera)
	{
		if(CameraExists(camera->Name()))
		{
			WRITELOG(L"Camera " + camera->Name() + L" allready exists", LOG_ERROR);
		}
		else
		{
			_lstCameras.push_back(camera);
			WRITELOG(L"Camera " + camera->Name() + L" added", LOG_INFO);

			if(_currentCamera==NULL)
				_currentCamera = camera;
		}
	}

	bool Scene::CameraExists(stringw& name)
	{
		for( std::list<Adrenalin::ICamera*>::iterator i = _lstCameras.begin(); 
			 i != _lstCameras.end();
			 i++ )
		{
			if( (*i)->Name().compare(name) == 0)
			{
				return true;
			}
		}

		return false;
	}

	stringw&	Scene::Name()
	{
		return _name;
	}

	void Scene::Update()
	{
		RenderVertex();
		//WRITELOG(L"Updating Scene " + _name, LOG_DEBUG);
	}

	void Scene::LoadEffectFile()
	{
		AdrenalinMain::Instance()->GetDevice()->LoadEffectFile();
	}

	void Scene::CreateVertex()
	{
		AdrenalinMain::Instance()->GetDevice()->CreateVertex();
	}

	void Scene::RenderVertex()
	{
		AdrenalinMain::Instance()->GetDevice()->RenderVertex();
	}
};